//
//  LazyScrollDemoVC.m
//  Demo
//
//  Created by lx on 2019/4/13.
//  Copyright © 2019 mgz. All rights reserved.
//

#import "LazyScrollDemoVC.h"
#import <TMLazyScrollView.h>
@interface LazyScrollDemoVC ()<TMLazyScrollViewDataSource>

@end

@implementation LazyScrollDemoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    TMLazyScrollView *scrollview = [[TMLazyScrollView alloc]init];
    scrollview.frame = self.view.bounds;
    scrollview.autoAddSubview = YES;
    scrollview.dataSource = self;
    [self.view addSubview:scrollview];
    [scrollview reloadData];
}

- (NSUInteger)numberOfItemsInScrollView:(TMLazyScrollView *)scrollView{
    return 20;
}

- (UIView *)scrollView:(TMLazyScrollView *)scrollView itemByMuiID:(NSString *)muiID{
    UIView *view = [scrollView dequeueReusableItemWithIdentifier:@"view"];
    NSInteger index = muiID.integerValue;
    if (!view) {
        view = [[UIView alloc]initWithFrame:CGRectMake(0, (index + 1)*40, 150, 30) reuseIdentifier:@"view"];
    }
    view.backgroundColor = [self randomColor];
    //[scrollView addSubview:view];
    return view;
}

- (TMLazyItemModel *)scrollView:(TMLazyScrollView *)scrollView itemModelAtIndex:(NSUInteger)index{
    TMLazyItemModel *model = [[TMLazyItemModel alloc]init];
    model.muiID = [NSString stringWithFormat:@"%zd",index];
    model.absRect = CGRectMake(0, (index + 1) * 40, 150, 30);
    return model;
}


- (UIColor *)randomColor{
    CGFloat hue = ( arc4random() % 256 / 256.0 ); //0.0 to 1.0
    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0,away from white
    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; //0.5 to 1.0,away from black
    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
